<template>
	<view>
		<home 
			v-if="PageCur=='home'" 
			pageCur="home" 
			:key="homeKey"
			@changeTabPage="changeTabPage"></home>
		<service-item  
			v-if="PageCur=='serviceItem'" 
			pageCur="serviceItem" 
			:key="serviceItemKey"
			@changeTabPage="changeTabPage"></service-item>
		<doctor-nurse 
			v-if="PageCur=='doctorNurse'" 
			pageCur="doctorNurse"
			:key="doctorNurseKey"
			@changeTabPage="changeTabPage"></doctor-nurse>
		<people 
			v-if="PageCur=='mine'" 
			pageCur="mine"
			:key="mineKey"
			@changeTabPage="changeTabPage"></people>
		
		<!-- 底部公共菜单 S -->
		<view class="cu-bar tabbar bg-white shadow foot">
			<view :class="PageCur=='home'?'action text-red':'action text-gray'" 
			@click="NavChange" 
			data-cur="home">
				<view class='cuIcon-homefill'></view>首页
			</view>
			<view :class="PageCur=='serviceItem'?'action text-red':'action text-gray'" 
				@click="NavChange" 
				data-cur="serviceItem">
				<view class='cuIcon-goodsnewfill'></view>
				商城
			</view>
			<view :class="PageCur=='doctorNurse'?'action text-red':'action text-gray'" @click="NavChange" data-cur="doctorNurse">
				<view class='cuIcon-medalfill'></view>
				医护
			</view>
			<view :class="PageCur=='mine'?'action text-red':'action text-gray'" @click="NavChange" data-cur="mine">
				<view class='cuIcon-myfill'></view>我的
			</view>
		</view>
		<!-- 底部公共菜单 E -->
	</view>
</template>

<script>
	import {
		USER_IDENTITY,
	} from "@/common/util/constants"
	
	export default {
		name: 'index',
		data() {
		return {
				PageCur: 'home',
				homeKey: 0,
				serviceItemKey: 0,
				doctorNurseKey: 0,
				mineKey: 0,
				
				userIdentity: -1,
			}
		},
		created() {
			//console.log('index created()')
		},
		onLoad:function(option){
			//console.log('index onLoad() option = ', option)
			//其它页面回传, 打开底部指定的菜单页面
			let _pageCur = ''
			if(option && option.pageCur){
				_pageCur = option.pageCur
			}
			if(_pageCur && _pageCur.length>0){
				this.PageCur = _pageCur
			}else{
				this.PageCur = 'home'	
			}
			
			++this.homeKey
			++this.serviceItemKey
			++this.doctorNurseKey
			++this.mineKey
			++this.aboutUs
			
			this.getUserInfo();
		},
		methods: {
			//底部菜单切换
			NavChange: function(e) {
				let _cur = e.currentTarget.dataset.cur
				let _forbidArr = []
				if(this.userIdentity==0){
					//0-会员
					_forbidArr = ['doctorNurse']
					if(_forbidArr.indexOf(_cur)!=-1){
						this.$tip.toast('仅对医护人员开放');
						return false
					}
				}else if(this.userIdentity==1 || this.userIdentity==2){
					//1-护士,2-医生
				}
				this.PageCur = _cur
			},
			//某个子页面通过代码，来切换父组件底部的tab菜单 
			changeTabPage(cur){
				this.PageCur = cur
			},
			// 用户信息
			getUserInfo(){
				this.userIdentity = uni.getStorageSync(USER_IDENTITY)
			},
		}
	}
</script>

<style>

</style>
